package com.qt.myio.ConvertStream;

import java.io.*;
import java.nio.charset.Charset;

/**
 * @Author zsf
 * @Date 2023/9/27 20:40
 * @Version 1.0
 */
public class ConverDemo01 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {

        //extracted();

        /**
         * 序列化javaBean
         */
        Student student = new Student("张三", 23, 100);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src/main/java/com/qt/myio/file/student.txt"));
        oos.writeObject(student);
        oos.close();

        //反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/main/java/com/qt/myio/file/student.txt"));
        Student stu = (Student)ois.readObject();
        ois.close();
        System.out.println(stu);


    }

    private static void extracted() throws IOException {
        /**
         * 利用字节流读取文件中的数据，每次读一整行，而且不能出现乱码
         * 1.字节流在读取中文的时候，是会出现乱码的，但是字符流可以搞定
         * 2.字节流里面是没有读一整行的方法的,只有字符缓冲流才能搞定
         */

        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("aaa/gbk.txt"), "GBK"));

        String s = br.readLine();
        br.close();
        System.out.println(s);
    }

}
